<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<%
	String path = request.getContextPath();		//项目名称
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.css"/>
<link rel="stylesheet" href="<%=basePath %>css/buttons.css" />
<script type="text/javascript" src="<%=basePath %>js/jquery-1.9.1.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
	$("#yd").click(function() {
        var $form = $("form");
        $.ajax({
            cache: true,
            type: "POST",
            url: $form.attr("action"),	//提交的url
            data: $form.serialize(),
            async: false,
            success: function (data) {
            	if( data.indexOf("成功") > 0 ){
            		alert("订票成功！");
            	}else{
            		alert("您已定过票，不能再次订票！");
            		location.reload();
            	}
            },
            error: function (request) {
                alert(request);
                location.reload();
            }
        });
    });
	$("#exit").click(function(){
		location.href = "<%=basePath %>index.jsp";
	});
});
</script>
<body>
	<center>
		<table>
			<tr>
				<td>
					<c:if test="${sessionScope.userBadrecord.fcount == 0}">
						<c:if test="${sessionScope.user.fweight >= sessionScope.sessionParam.fweight or sessionScope.user.fheight >= sessionScope.sessionParam.fheight
						 	or sessionScope.user.fidentity == '老年人' or sessionScope.user.fidentity == '残疾人、军人'}">
							<label><font color="red" size="2">乘客您好，根据您的情况，我们优先为您选择下铺座位</font></label>
						</c:if>
					</c:if>
					<br/>
					<c:if test="${sessionScope.userBadrecord.fcount == 1 or sessionScope.userBadrecord.fcount == 1}">
						<img src="<%=basePath%>/img/jingshi.png"  style="width: 40px; height: 50px;"/>
						<c:if test="${sessionScope.userBadrecord.fcount == 1}">
							<label><font color="red" size="2">尊敬的乘客，由于您有一次违规订票记录，本次订票不能选择【下铺】座位</font></label>
						</c:if>
						<c:if test="${sessionScope.userBadrecord.fcount == 2}">
							<label><font color="red" size="2">尊敬的乘客，由于您有两次违规订票记录，本次订票不能选择【下铺】及【软卧】座位</font></label>
						</c:if>
					</c:if>					
				</td>
			</tr>
		</table>
		<form action="<%=basePath %>ticketinfo/add" method="post">
			<table border="0">
				<c:forEach items="${trainList }" var="train">
					<tr>
						<td>车次：</td>
						<td>${train.trainnumber }
							<div style="display: none;"><input type="text" name="ftrainnumber" value="${train.trainnumber }"/></div>
						</td>
						<td></td><td></td>
					</tr>	
					<tr>
						<td>起点：</td><td>${train.startstation }</td><td>终点：</td><td>${train.endstation }</td>
					</tr>	
					<tr>
						<td>卧铺类型：</td>
						<td colspan="3">
							<select id="ftype" name="ftype"  class="form-control" style="width:160px;height:30px;">
								<c:if test="${sessionScope.user.fweight >= sessionScope.sessionParam.fweight or sessionScope.user.fheight >= sessionScope.sessionParam.fheight
									 or sessionScope.user.fidentity == '老年人' or sessionScope.user.fidentity == '残疾人、军人'}">
									 <c:if test="${sessionScope.userBadrecord.fcount == 0}">
									 	<option value="下铺">下铺</option>
									 </c:if>
									 <option value="中铺">中铺</option>
									 <option value="上铺">上铺</option>	
								</c:if>	
								<c:if test="${sessionScope.user.fweight < sessionScope.sessionParam.fweight and sessionScope.user.fheight < sessionScope.sessionParam.fheight
									 and sessionScope.user.fidentity != '老年人' and sessionScope.user.fidentity != '残疾人、军人'}">
									 <option value="上铺">上铺</option>
									 <option value="中铺">中铺</option>
									 <c:if test="${sessionScope.userBadrecord.fcount == 0}">
									 	<option value="下铺">下铺</option>
									 </c:if>
								</c:if>				
							</select>
						</td>
					</tr>
					<tr>
						<td>座位类型：</td>
						<td colspan="3">
							<select id="ftype" name="ftype"  class="form-control" style="width:160px;height:30px;">
								<c:if test="${sessionScope.user.fweight >= sessionScope.sessionParam.fweight or sessionScope.user.fheight >= sessionScope.sessionParam.fheight
									 or sessionScope.user.fidentity == '老年人' or sessionScope.user.fidentity == '残疾人、军人'}">
									 <c:if test="${sessionScope.userBadrecord.fcount == 0 or sessionScope.userBadrecord.fcount == 1}">
									 	<option value="软卧">软卧</option>
									 </c:if>
									 <option value="硬卧">硬卧</option>
								</c:if>	
								<c:if test="${sessionScope.user.fweight < sessionScope.sessionParam.fweight and sessionScope.user.fheight < sessionScope.sessionParam.fheight
									 and sessionScope.user.fidentity != '老年人' and sessionScope.user.fidentity != '残疾人、军人'}">
									 <option value="硬卧">硬卧</option>
									 <c:if test="${sessionScope.userBadrecord.fcount == 0 or sessionScope.userBadrecord.fcount == 1}">
									 	<option value="软卧">软卧</option>
									 </c:if>
								</c:if>				
							</select>
						</td>
					</tr>
					<tr>
						<td colspan="4" align="center">
							<input type="radio" name="fpay" id="optionsRadios1" value="1" checked >立即支付&nbsp;&nbsp;
						    <input type="radio" name="fpay" id="optionsRadios2" value="0" >稍后支付
						</td>
					</tr>
					<tr>
						<td colspan="4" align="center">
							应付金额：${train.price }
						</td>
					</tr>
					<tr>
						<td colspan="4" align="center">
						<input type="button" value="预定"
						class="button button-pill button-primary" style="width:140px;height:40px;" id="yd"/>
						&nbsp;&nbsp;
						<input type="button" value="返回" id="exit"
						class="button button-pill button-primary" style="width:140px;height:40px;"/>
						</td>
					</tr>
				</c:forEach>
			</table>
		</form>
	</center>
</body>
</html>